<template>
  <div>
    <el-form :model="itemInfo" :inline="true" size="small" label-width="150px">
      <el-form-item label="供应商号:">
        <div style="width: 200px">
          <span v-if="itemInfo.mpsFormInfo" class="filter-item">{{ itemInfo.mpsFormInfo.vendorNbr }}</span>
        </div>
      </el-form-item>
      <el-form-item label="供应商邮箱地址:">
        <el-input v-if="itemInfo.mpsFormInfo" v-model="itemInfo.mpsFormInfo.vendorEmail" size="mini" style="width: 200px" class="filter-item" />
      </el-form-item>
      <el-form-item label="供应商附件:">
        <el-tooltip v-if="itemInfo.filePath" content="点击查看/下载" effect="dark" placement="bottom">
          <i class="el-icon-files" style="font-size: 23px; margin-right: 3px" @click="previewFile(itemInfo.filePath)" />
        </el-tooltip>
      </el-form-item>
      <el-form-item label="采购附件:">
        <el-tooltip v-if="itemInfo.buyerFilePath" content="点击查看/下载" effect="dark" placement="bottom">
          <i class="el-icon-files" style="font-size: 23px; margin-right: 3px" @click="previewFile(itemInfo.buyerFilePath)" />
        </el-tooltip>
      </el-form-item>
    </el-form>
    <el-collapse>
      <el-collapse-item title="供应商提交数据" name="1">
        <el-form :model="vendorItemInfo" :inline="true" size="small" label-position="right" label-width="200px">
          <el-form-item label="条码:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.upcNbr }}</span>
            </div>
          </el-form-item>
          <el-form-item label="供应商号:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.vendorNbr }}</span>
            </div>
          </el-form-item>
          <el-form-item label="供应商名称:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.vendorName }}</span>
            </div>
          </el-form-item>
          <el-form-item label="商品说明1:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.item1Desc }}</span>
            </div>
          </el-form-item>
          <el-form-item label="供应商之商品代码:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.vendorStockId }}</span>
            </div>
          </el-form-item>
          <el-form-item label="货架1/颜色:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.shlflbl1ColrDesc }}</span>
            </div>
          </el-form-item>
          <el-form-item label="规格型号:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.shlflbl3SizeDesc }}</span>
            </div>
          </el-form-item>
          <el-form-item label="原包高度:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.vnpkHeightQty }}</span>
            </div>
          </el-form-item>
          <el-form-item label="原包宽度:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.vnpkWidthQty }}</span>
            </div>
          </el-form-item>
          <el-form-item label="原包深度:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.vnpkLengthQty }}</span>
            </div>
          </el-form-item>
          <el-form-item label="原包重量:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.vnpkWeightQty }}</span>
            </div>
          </el-form-item>
          <el-form-item label="供应商箱包数量:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.vnpkQty }}</span>
            </div>
          </el-form-item>
          <el-form-item label="仓包内装量:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.whpkQty }}</span>
            </div>
          </el-form-item>
          <el-form-item label="供应商包装成本:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.vnpkCostAmt }}</span>
            </div>
          </el-form-item>
          <el-form-item label="进项税:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.vatIn }}</span>
            </div>
          </el-form-item>
          <el-form-item label="产地:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.mdsDesc }}</span>
            </div>
          </el-form-item>
          <el-form-item label="部门:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.deptNbr }}</span>
            </div>
          </el-form-item>
          <el-form-item label="供应商联系人:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.vendorPerson }}</span>
            </div>
          </el-form-item>
          <el-form-item label="供应商电话:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.vendorTel }}</span>
            </div>
          </el-form-item>
          <el-form-item label="供应商邮箱:">
            <div style="width: 200px">
              <span class="filter-item">{{ vendorItemInfo.vendorEmail }}</span>
            </div>
          </el-form-item>
        </el-form>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script>
import { Message } from 'element-ui'
import { uploadFile } from '@/api/change-item'
import { previewFile } from '@/utils/item'

export default {
  data() {
    return {
      vendorItemInfo: {},
      itemInfo: {},
      filePath: null,
      itemStatus: null
    }
  },
  methods: {
    // 查看附件
    previewFile,
    // 文件变动的钩子-附件上传
    attachmentHandleOnChange(file, fileList) {
      var size = file.size / 1024 / 1024
      if (size > 5) {
        Message({
          message: '文件大小必须小于5M。',
          type: 'warning',
          duration: 3 * 1000
        })
        fileList.pop()
        return
      }
      this.$confirm('附件上传会覆盖原有附件，是否上传？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        var formData = new FormData()
        formData.append('file', file.raw)
        uploadFile(formData).then(
          (res) => {
            if (res) {
              const filePath = res[0].fileUrl
              this.itemInfo.filePath = filePath
              this.filePath = filePath
            }
          },
          (error) => {
            console.log(error)
            this.loading = false
            this.itemInfo.filePath = null
            this.filePath = null
          }
        )
        fileList.pop()
      })
    }
  }
}
</script>
